<!--<html>-->
<% var _id = [0, 1, 2, 6, 3, 4, 5, 7, 8, 9, 13, 14]; %>
<fieldset id="widthfix">
  <% var F = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", probNum = 0; %>
  <% var startTime = contest.startTime %>
  <% var pending = parseInt((startTime - time)/1000, 10); %>
  <% var c = '', s = '', ts, ps = ''; %>
  <% if (pending > 0) { %>
  <% c = 'info'; s = 'Pending'; ts = 0; %>
  <% } else if (pending + contest.len*60 > 0) { %>
  <% c = 'wrong'; s = 'Running'; ts = 1; %>
  <% } else { %>
  <% c = 'accept'; s = 'Ended'; ts = 2; %>
  <% } %>
  <% if (ts == 1) { %>
  <% ps = 'progress-danger'; %>
  <% } else if (ts == 2) { %>
  <% ps = 'progress-success'; %>
  <% } %>
  <% var watch; %>
  <% if (user && (user.name == contest.userName || user.name == 'admin')) { watch = true; } %>
  <div>
    <legend id="contest" ctype="<%= contest.type %>" pageNum="<%= pageNum %>" startTime="<%= startTime %>" cid="<%= contest.contestID %>" len="<%= contest.len %>" pending="<%= pending %>" status="<%= ts %>" <% if (watch) { %>watch="1"<% } %>>
      比赛
    </legend>
  </div>
<% contest.probs.forEach(function(p, i) { ++probNum; %>
  <span class="cpid" pid="<%= p[0] %>" <% if (p[1]) { %>alias="<%= p[1] %>"<% } %>></span>
<% }); %>
  <div class="marquee">
    <marquee id="marquee" onmouseout="this.start()" onmouseover="this.stop()" scrollamount="2" scrolldelay="1" behavior="alternate">
      <%- contest.msg %>
    </marquee>
  </div>
  <div>
    <h3 class="problem-header"><%= contest.title %></h3>
  </div>
  <div id="contest-info" style="float:left;text-align:right;">
  </div>
  <div id="progress" class="contest_progress progress progress-striped active <%= ps %> cb">
    <div class="bar"></div>
  </div>
  <div  id="thumbnail" class="tabbable thumbnail">
    <span class="fr user user-green" style="margin: 10px;">罚时：<%= contest.penalty %>分钟/次</span>
    <ul class="nav nav-tabs">
      <li style="padding-left:10px;">
        <a href="#overview" class="tablink">
          <span>Overview</span>
        </a>
      </li>
      <li class="hidden">
        <a href="#problem" class="tablink">
          <span>Problem</span>
        </a>
      </li>
      <li class="hidden">
        <a href="#status" class="tablink">
          <span>Status</span>
        </a>
      </li>
      <li class="hidden">
        <a href="#rank" class="tablink">
          <span>Rank</span>
        </a>
      </li>
      <li class="hidden">
        <a href="#discuss" class="tablink">
          <span>Discuss</span><sup class="tips hide" id="discuss_tips"></sup>
        </a>
      </li>
    </ul>
    <div class="tab-content">
<!--overviewtab-->
      <div class="tab-pane" id="overviewtab">
        <div style="margin: 0 18%;">
          <table class="table table-head thright" id="overviewtable">
            <tr>
              <th width="20%">Current Time:</th>
              <td class="bold user-gray" id="contest_current"></td>
              <th width="21%">Contest Type:</th>
              <td>
              <% if (contest.password) { %>
                <span class="user user-green">Private</span>
              <% } else { %>
                <span class="user user-blue">Public</span>
              <% } %>
              </td>
            </tr>
            <tr>
              <th>Start Time:</th>
              <td class="bold user-gray"><%= getDate(startTime) %></td>
              <th>Contest Status:</th>
              <td class="bold <%= c %>-text"><%= s %></td>
            </tr>
            <tr>
              <th>End Time:</th>
              <td class="bold user-gray"><%= getDate(startTime+contest.len*60000) %></td>
              <th>Manager:</th>
              <td>
                <a class="user user-<%= MC %>" title="<%= MT %> <%= contest.userName %>" href="/user/<%= contest.userName %>">
                  <%= contest.userName %>
                </a>
              </td>
            </tr>
          </table>
        </div>
        <div class="row-fluid" align="center" style="margin-bottom:15px;">
      <% if (watch) { %>
          <a class="uibtn" href="/addcontest?cID=<%= contest.contestID %>&type=<%= contest.type %>">Edit</a>
          <a class="uibtn" href="javascript:;" id="delete">Delete</a>
      <% } %>
      <% if (s == 'Ended') { %>
        <a href="javascript:;" class="uibtn checklogin" id="clone" title="To create a DIY Contest with the same problems.">Clone this contest</a>
      <% } %>
        </div>
      <% if (ts == 0 && !watch) { %>
        <div class="user-gray" style="text-align:center;font-size:1.75em;margin:100px;">
          Before Contest <span id="lefttime"></span>
        </div>
      <% } %>
        <div class="hidden" id="problemsview">
          <div class="tablebg">
            <div class="theader">Problem List</div>
            <div id="tablediv">
              <table class="table table-cf" id="problems">
                <thead>
                  <tr>
                    <th style="width:70px;">#</th>
                    <th>Name</th>
                    <th style="width:70px;"></th>
                    <th style="width:90px;">Solved</th>
                  </tr>
                </thead>
              <% contest.probs.forEach(function(p, i) { %>
                <tr class="<% if (i % 2 == 0) { %>odd<% } else { %>even<% } %>">
                  <td class="center bold o_index">
                    <%= F[i] %>
                  </td>
                  <td>
                    <% if (user && (user.name == 'admin' || user.name == Pt[p[0]].manager)) { %>
                    <a class="fr uibtn uibtn-mini toggleHide" href="javascript:;" pid="<%= p[0] %>"><% if (Pt[p[0]].hide) { %>显示到题库<% } else { %>隐藏<% } %></a>
                    <% } %>
                    <a href="#problem-<%= F[i] %>"><%= p[1] ? p[1] : Pt[p[0]].title %></a>
                  </td>
                  <td>
                    <span class="act-item">
                      <a class="consubmit" href="javascript:;" pid="<%= p[0] %>" tname="<%= Pt[p[0]].title %>">
                        <img src="/img/submit.png" title="Submit" alt="Submit"/>
                      </a>
                    </span>
                  </td>
                  <td class="center o_sol"></td>
                </tr>
              <% }); %>
              </table>
            </div>
          </div>
      <% if(contest.description) { %>
          <div class="des-box"><p><%= contest.description %></p></div>
      <% } %>
        </div>
      </div>
<!--problemtab-->
      <div class="row-fluid tab-pane" id="problemtab">
        <div class="pagination pagination-centered">
          <ul>
          <% contest.probs.forEach(function(prob, i) { %>
            <li class="problemlink">
              <a href="#problem-<%= F[i] %>"><%= F[i] %></a>
            </li>
          <% }); %>
          </ul>
        </div>
        <div id="prob-contain" class="istyle">
          <div align="center">
            <h3 class="problem-header" id="problem_title"><span class="user-green"></span>&nbsp;-&nbsp;<span></span></h3>
            <div style="padding-bottom:8px;">
              <b>Time Limit: </b><span class="limit"></span> MS (Java/Others) &nbsp;&nbsp;&nbsp;&nbsp;
              <b>Memory Limit: </b><span class="limit"></span> KB (Java/Others)
              <span class="user user-red limit"></span>
            </div>
            <div id="pids">
              <a id="probsubmit" class="uibtn consubmit" href="javascript:;">Submit</a>
              <a class="uibtn" href="javascript:;">Status</a>
            <% if (user && user.name == 'admin') { %>
              <a id="rejudge" class="uibtn" href="javascript:;">Rejudge</a>
            <% } %>
            </div>
          </div>
          <div id="content" style="padding:15px 40px;">
          </div>
          <div align="center" style="padding-bottom:20px;">
            <a id="probsubmit2" class="uibtn consubmit" href="javascript:;">Submit</a>
            <a class="uibtn" href="javascript:;">Status</a>
          </div>
        </div>
      </div>
<!--statustab-->
      <div class="tab-pane" id="statustab" style="margin: 0 10px;">
        <div class="tablebg">
          <div id="pager">
            <div id="list" class="pagination pagination-small fl">
            </div>
            <div class="fr" id="filter">
              <div class="input-prepend">
                <span class="add-on">Name</span>
                <input type="text" id="search" placeholder=" username">
              </div>
              <div class="input-prepend">
                <span class="add-on">Problem</span>
                <select id="pid" style="width:160px;">
                  <option value="nil" selected>All</option>
                <% contest.probs.forEach(function(p, i) { %>
                  <option value="<%= F[i] %>"><%= F[i] %> - <%= Pt[p[0]].title %></option>
                <% }); %>
                </select>
              </div>
              <div class="input-prepend">
                <span class="add-on">Verdict</span>
                <select id="result" style="width:160px;">
                  <option value="nil" selected>All</option>
                <% _id.forEach(function(p) { %>
                  <option class="<%= Col(p) %>" value="<%= p %>"><%= Res(p) %></option>
                <% }); %>
                </select>
              </div>
              <div>
                <a class="uibtn uibtn-mini" href="javascript:;" id="fil">Filter</a>
              </div>
              <div>
                <a class="uibtn uibtn-mini" href="#status">Reset</a>
              </div>
            </div>
          </div>
          <div id="tablediv">
            <table class="table table-cf" id="statustable">
              <thead>
                <tr>
                  <th style="width:7%;">RunID</th>
                  <th style="width:14%;">User</th>
                  <th style="width:10%;">Problem</th>
                  <th>Verdict</th>
                  <th style="width:9%;">Time</th>
                  <th style="width:9%;">Memory</th>
                  <th style="width:8%;">Lang</th>
                  <th style="width:8%;">Length</th>
                  <th style="width:15%;">Submit Time</th>
                </tr>
              </thead>
              <tbody></tbody>
            </table>
          </div>
        </div>
      </div>
<!--ranktab-->
      <% var mw = 6 + 41 + 181 + 81 + 41 + 61 + 81*probNum; %>
      <div class="tab-pane" id="ranktab" style="margin:0px 10px;">
      <div id="rankheader" style="width:<%= mw-6 %>px">
        <table class="table table-rank">
          <%- partial('rankheader', {probNum: probNum, F: F}) %>
        </table>
      </div>
      <% if (watch) { %>
        <% if (contest.type == 2) { %>
        <div class="form-inline">
          <button class="btn" id="calrating">统计rating</button>
        </div>
        <% } %>
        <div class="form-inline">
          <input class="input-xxlarge" type="text" id="starstr" placeholder="用户名" title="用户名"/>
          <select class="input-medium" id="type">
            <option value="1">给他们打星</option>
            <option value="2">取消打星</option>
          </select>
          <button class="btn" id="star">提交</button>
          <small class="user-gray">PS: 多个用户请用空格隔开</small>
          <span class="error-text" id="starerr"></span>
        </div>
        <div class="form-inline">
          <input class="input-xxlarge" type="text" id="msg_data" placeholder="在此填写消息内容" title="在此填写消息内容"/>
          <button class="btn" id="broadcast">广播消息</button>
          <span class="error-text" id="msg_err"></span>
        </div>
      <% } %>
        <div class="tablebg" style="width:<%= mw %>px">
          <div class="fr" style="margin:5px;">
            <span id="gtime" class="user user-gray">The Rank will be updated every 30 seconds</span>
            <a id="rank_refresh" href="javascript:;" class="uibtn uibtn-mini">刷新一下</a>
          </div>
          <div id="ranklist" class="pagination pagination-small">
          </div>
          <div id="tablediv">
            <table class="table table-rank tdcenter">
              <thead>
                <%- partial('rankheader', {probNum: probNum, F: F}) %>
              </thead>
              <tbody></tbody>
            </table>
          </div>
        </div>
      </div>
<!-- discusstab -->
      <div class="tab-pane" id="discusstab" style="margin:0px 10px;">
        <div class="tablebg">
          <div class="fr" style="margin:5px;">
            <a id="discuss_refresh" href="javascript:;" class="uibtn uibtn-mini">刷新一下</a>
          </div>
          <div id="dislist" class="pagination pagination-small">
          </div>
          <div id="tablediv">
            <table class="table" style="table-layout:fixed;" id="contest">
              <thead>
                <tr>
                  <th style="width:60px;"></th>
                  <th style="width:10%;">回复/浏览</th>
                  <th style="text-align:left;">标题</th>
                  <th style="width:15%;"></th>
                </tr>
              </thead>
              <tbody>
                <tr class="odd">
                  <td class="error-text" colspan="6">No Topics are matched.</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      <% if (user && isContestant) { %>
        <div class="topic_box form-horizontal">
          <div class="header">
            <span class="user user-gray">发表疑问</span>
            <span class="user user-green">（用于提问关于题目描述不清的问题，如："n的范围是多少？"，"x是整数吗？"等等）</span>
          </div>
          <div class="inner_topic">
            <div class="control-group">
              <label class="control-label" for="publish_pid"><span class="user user-gray">题号：</span></label>
              <div class="controls">
                <select class="input-mini" id="publish_pid">
                <% for (var i = 0; i < contest.probs.length; i++) { %>
                  <option value="<%= F[i] %>"><%= F[i] %></option>
                <% } %>
                </select>
              </div>
            </div>
            <div class="control-group">
              <label class="control-label" for="publish_title"><span class="user user-gray">标题：</span></label>
              <div class="controls">
                <input type="text" id="publish_title" class="input-xlarge" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label" for="publish_content"><span class="user user-gray">内容：</span></label>
              <div class="controls">
                <textarea id="publish_content" rows="5" style="width:400px;"></textarea>
              </div>
            </div>
            <div class="control-group">
              <div class="controls">
                <a style="margin:0;" class="uibtn" href="javascript:;" id="publish">发表</a>
                <span class="error-text" id="publish_err"></span>
              </div>
            </div>
          </div>
        </div>
      <% } %>
      </div>
      <div id="loading" class="mc hide" style="width:287px;">
        <img src="/img/Loading.gif" alt="Loading..." />
      </div>
      <div id="retry" class="mc hide alert alert-error" style="width:287px;font-size:32px;padding:100px;text-align:center;">
        请求失败，<a href="javascript:;">重试</a>
      </div>
    </div>
  </div>
</fieldset>